<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="include/base.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
	<title>document</title>
	<link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/style.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/time.js"></script>
</head>
<body>
	<div class="container">
		<%@ include file="include/top.jsp" %>
	<!--header end-->
		<div class="content">
			<div class="row">
				<div class="span9">
				<ul class="breadcrumb">
				  <li><a href="documentlist.jspx"><i class="icon-folder-open"></i>资料</a> <span class="divider">/</span></li>
				  <li class="active">资料标题</li>
				</ul>
				<div class="page_show">
					<input type="hidden" id="document_id" value="${document.id }">
					<input type="hidden" id="cur_employee_id" value="${sessionScope.employee.id }">
					<h4>${document.title }&nbsp;&nbsp;<small title="${document.createtime }" id="${document.id}"></small></h4>
					<script type="text/javascript">
					  	var endtime = getNow();
					  	var starttime = '${document.createtime }';
					  	var diftime = getTimeDif(starttime,endtime);
					  	var id = '${document.id}';
					  	var name = '${document.employee.name }';
					  	$("#"+id).text(name+diftime);
					  </script>
					<p>${document.content }</p>
				</div>
				<h4>评论</h4>
				<form action="">
					<textarea rows="3" style="width:90%" id="text"></textarea><br />
					<div class="alert hide" style="width:300px">
					  <button type="button" class="close" data-dismiss="alert">&times;</button>
					  <strong>请输入评论！</strong>
					</div>
					<button type="button" class="btn btn-info" id="btn">发布</button>
				</form>
				<div id="show">
					<c:forEach items="${list }" var="comment">
						<blockquote>
							${comment.content }<small title="${comment.createtime }" id="${comment.id }"></small>
							<script type="text/javascript">
							  	var endtime = getNow();
							  	var starttime = '${comment.createtime }';
							  	var diftime = getTimeDif(starttime,endtime);
							  	var id = '${comment.id}';
							  	var name = '${comment.employee.name }';
							  	$("#"+id).text(name+diftime);
							  </script>
							<c:if test="${comment.employee_id == sessionScope.employee.id }">
								<a href="commentedit.jspx?id=${comment.id }" class="icon-pencil"></a>
								<a href="javascript:;" class="icon-trash" onclick="del()" rel="${comment.id }"></a>
							</c:if>
						</blockquote>
					</c:forEach>
				</div>
				<c:if test="${empty list }">
					<blockquote id="none">还没有评论，快来发表自己的意见吧！</blockquote>
				</c:if>
				<a href="documentlist.jspx">←返回资料列表</a>
				</div>
				<div class="span3">
				</div>
			</div>
		</div>
		<!--container end-->
		<div class="footer">
			<p>Copyright © 2013 xxx版权所有</p>
		</div>
		<!--footer end-->
	</div>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#btn").click(function(){
				var document_id = $("#document_id").val();//资料的id
				var text = $("#text").val();          //评论的内容
				if(!text){
					$(".alert").show();
					$("#text").focus();
				}else{
					$.post("adddocumentcomment.jspx",{document_id:document_id,text:text},function(data){
						$("#show").html("");
						$(data).each(function(){
							var id = this.id;
							var content = this.content;
							var employeename = this.employee.name;
							var starttime = this.createtime;
							var endtime = getNow();
							var diftime = getTimeDif(starttime,endtime);
							var employee_id = this.employee_id;
							var cur_employee_id = $("#cur_employee_id").val();
							if(employee_id==cur_employee_id){
								$("#show").append("<blockquote>"+content+"<small>"+employeename+"发布于"+diftime+"</small>"+
								"<a href='commentedit.jspx?id="+id+"' class='icon-pencil'></a><a href='javascript:;' class='icon-trash' rel='"+id+"'></a></blockquote>");
							}else{
								
								$("#show").append("<blockquote>"+content+"<small>"+employeename+"发布于"+diftime+"</small></blockquote>");
							}
							$("#none").hide();
							$("#text").val("");
						});
					});
				}
			});
			//删除评论
			$(".icon-trash").live('click',function(){
				var id = $(this).attr("rel");
				if(window.confirm("你确定要删除吗？")){
					window.location = "delcomment.jspx?id="+id;
				}
			});
		});
	</script>
</body>
</html>